import { Component, NgZone } from '@angular/core';

import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { Deeplinks } from '@ionic-native/deeplinks/ngx'
import { Router } from '@angular/router';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss']
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    private deeplinks: Deeplinks,
    private zone: NgZone,
    private router: Router
  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
      this.setDefaultLink()
    });
  }
  setDefaultLink(){
    this.deeplinks.route({
      ':/slug': 'posts',
      'products/:id': ''
    }).subscribe(match => {
      console.log('match',match)
      const intepath = `/${match.$route}/${match.$args['slug']}`
      this.zone.run(()=>{
        this.router.navigateByUrl(intepath)
      })
    })
  }
}
